package com.xiaochen.baidu.service.thread;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xiaochen.baidu.service.IMoiuParseService;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;

import java.util.HashMap;
import java.util.function.Supplier;

/**
 * @author xc
 * @date 2025/10/12/21:44
 * @desc
 */
@AllArgsConstructor
public class ParseThreadTask implements Supplier<String> {
    private String surl;
    private Long uk;
    private Long shareId;
    private String randsk;
    private Long fsId;
    private String serverFilename;
    private Long size;
    private String session;
    private IMoiuParseService moiuParseService;
    @SneakyThrows
    @Override
    public String get() {
        HashMap<String, Object> map = new HashMap<String, Object>() {{
            put("surl", surl);
            put("uk", uk);
            put("shareid", shareId);
            put("sekey", randsk);
            put("fsidlist", fsId);
            put("filename", serverFilename);
            put("size", size);
            put("password", "");
        }};
        Call<ResponseBody> call = moiuParseService.link(session, map);
        ResponseBody responseBody = call.execute().body();
        ObjectMapper objectMapper = new ObjectMapper();
        JsonNode jsonNode = objectMapper.readTree(responseBody.string());
        return jsonNode.get("data").get("dlink").asText();
    }
}
